package com.augurit.gzcgwsp.webservice;

import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.fault.XFireFault;
import org.codehaus.xfire.handler.AbstractHandler;
import org.jdom.Element;

public class AuthenticationHandler extends AbstractHandler {

	@Override
	public void invoke(MessageContext context) throws Exception {
		if (context.getInMessage().getHeader() == null) {  
			           throw new XFireFault("----------请求必须包含身份验证信息！----------", XFireFault.SENDER);  
		}  
       Element token = context.getInMessage().getHeader().getChild("AuthenticationToken");  
        if (token == null) {  
          throw new XFireFault("----------请求必须包含身份验证信息！----------", XFireFault.SENDER);  
        }  
       String username = token.getChild("Username").getValue();  
       String password = token.getChild("Password").getValue();  
       try {  
         
           String nameValue = "test";  
            String pawdValue ="test";  
          if (username.equals(nameValue) && password.equals(pawdValue)) {  
                System.out.println("----------身份验证通过！----------");  
            } else {  
                throw new Exception();  
           }  
        } catch (Exception e) {  
            throw new XFireFault("----------非法的用户名或密码！----------", XFireFault.SENDER);  
        }  

		
	}

}
